package com.hankol.newretail.adapter.order

import android.annotation.SuppressLint
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.baselibrary.R
import com.baselibrary.bean.MyOrderTabBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * @author: 关忆北、
 * @date: 2022/8/8
 * @Des：我的订单tba
 */
class MyEvaluationTabAdapter : BaseQuickAdapter<MyOrderTabBean, BaseViewHolder>(R.layout.item_my_evaluation_tab) {
    private var callBack: OnLoadItemViewCallBack? = null
    override fun convert(helper: BaseViewHolder, item: MyOrderTabBean) {
        val tvMyOrderTitle = helper.getView<TextView>(R.id.tv_my_evaluation_title)
        helper.setText(R.id.tv_my_evaluation_title, item.tabName)
        tvMyOrderTitle.paint.isFakeBoldText = item.isSelected
        tvMyOrderTitle.setTextColor(ContextCompat.getColor(mContext, if (item.isSelected) R.color.color_F54D53 else R.color.color_333333))
        tvMyOrderTitle.textSize = if (item.isSelected) 16f else 14f
        if (item.isSelected) {
            callBack?.onSelectedDrawComplete(helper.getView(R.id.ll_my_evaluation_title), helper.adapterPosition)
        }
    }

    @SuppressLint("NotifyDataSetChanged") fun upSelectedTab(selectedPos: Int) {
        for (index in 0 until data.size) {
            data[index].isSelected = index == selectedPos
        }
        notifyDataSetChanged()
    }

    fun setOnLoadItemViewCallBack(callBack: OnLoadItemViewCallBack) {
        this.callBack = callBack
    }

    interface OnLoadItemViewCallBack {
        fun onSelectedDrawComplete(view: View, position: Int)
    }
}